﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebMVC.Areas.AdminPanel.Models;
using BusinessTier.Facade.Interface;
using BusinessTier.Facade.Implementation;
using Domain;
using WebMVC.Helpers;

namespace WebMVC.Areas.AdminPanel.Controllers
{
    public class DictionaryController : AdminControllerBase
    {
        private IStaticDataService staticDataService;

        public DictionaryController()
            : this(new StaticDataService())
        {}

        public DictionaryController(IStaticDataService staticDataService)
        {
            this.staticDataService = staticDataService;
        }

        public ActionResult Index()
        {
            var dictModel = new DictionaryViewModel()
            {
                ColorThemes = new List<ColorThemeViewModel>(),
                Industries = new List<IndustryViewModel>(),
                Styles = new List<StyleViewModel>(),
                Tags = new List<TagViewModel>(),
                MediaTypes = new List<PrintMediaTypeViewModel>(),
                DesignGroups = new List<DesignGroupViewModel>(),
                Fonts = new List<FontViewModel>()

            };

            foreach (var style in staticDataService.GetAllStyles())
            {
                dictModel.Styles.Add(new StyleViewModel() { 
                    Id = style.StyleId,
                    NameEn = style.NameEn,
                    NameAm = style.NameAm,
                    NameRu = style.NameRu
                });
            }

            foreach (var ind in staticDataService.GetAllIndustries())
            {
                dictModel.Industries.Add(new IndustryViewModel()
                {
                    Id = ind.IndustryId,
                    NameEn = ind.NameEn,
                    NameAm = ind.NameAm,
                    NameRu = ind.NameRu
                });
            }

            foreach (var col in staticDataService.GetAllColorThemes())
            {
                dictModel.ColorThemes.Add(new ColorThemeViewModel()
                {
                    Id = col.ColorThemeId,
                    NameEn = col.NameEn,
                    NameAm = col.NameAm,
                    NameRu = col.NameRu,
                    RGBHex = col.RGBHex
                });
            }

            foreach (var tag in staticDataService.GetAllTags())
            {
                dictModel.Tags.Add(new TagViewModel()
                {
                    Id = tag.TagId,
                    NameEn = tag.NameEn,
                    NameAm = tag.NameAm,
                    NameRu = tag.NameRu
                });
            }
            /*
            foreach (var des in staticDataService.GetAllDesignGroups())
            {
                dictModel.DesignGroups.Add(new DesignGroupViewModel()
                {
                    Id = des.Id,
                    NameEn = des.NameEn,
                    NameAm = des.NameAm,
                    NameRu = des.NameRu
                });
            }*/

            foreach (var type in staticDataService.GetAllPrintMediaTypes())
            {
                dictModel.MediaTypes.Add(new PrintMediaTypeViewModel()
                {
                    Code = type.PrintMediaTypeId,
                    NameEn = type.NameEn,
                    NameAm = type.NameAm,
                    NameRu = type.NameRu,
                    /*DescriptionAm =type.DescriptionAm,
                    DescriptionEn = type.DescriptionEn,
                    DescriptionRu = type.DescriptionRu*/
                });
            }

            foreach (var font in staticDataService.GetAllFonts())
            {
                dictModel.Fonts.Add(new FontViewModel()
                {
                    Id = font.FontId,
                    IsUnicode = font.IsUnicode,
                    LanguageCode = font.LanguageCode,
                    Name = font.Name,
                    Style = font.Style,
                    CreateDate = font.CreateDate
                });
            }


            return View(dictModel);
        }

        [HttpGet]
        public ActionResult CreateStyle()
        {
            return View();
        }
        /*
        [HttpPost]
        public ActionResult CreateStyle(StyleViewModel model)
        {
            if(ModelState.IsValid){
                var obj = new Style() { 
                    NameAm = model.NameAm,
                    NameEn = model.NameEn,
                    NameRu = model.NameRu
                };
                var newId = staticDataService.CreateStyle(obj);
                Info = "Style " + model.NameEn + " successfully added with ID[" + newId + "]";
                return RedirectToAction("CreateStyle");
            }
           
            return View(model);
        }
        */

        [HttpGet]
        public ActionResult CreateIndustry()
        {
            return View();
        }
        /*
        [HttpPost]
        public ActionResult CreateIndustry(IndustryViewModel model)
        {
            if (ModelState.IsValid)
            {
                var obj = new Industry()
                {
                    NameAm = model.NameAm,
                    NameEn = model.NameEn,
                    NameRu = model.NameRu
                };
                var newId = staticDataService.CreateIndustry(obj);
                Info = "Industry " + model.NameEn + " successfully added with ID[" + newId + "]";
                return RedirectToAction("CreateIndustry");
            }

            return View(model);
        }*/

        [HttpGet]
        public ActionResult CreateColorTheme()
        {
            return View();
        }
        /*
        [HttpPost]
        public ActionResult CreateColorTheme(ColorThemeViewModel model)
        {
            if (ModelState.IsValid)
            {
                var obj = new ColorTheme()
                {
                    NameAm = model.NameAm,
                    NameEn = model.NameEn,
                    NameRu = model.NameRu,
                    RGBHex = model.RGBHex
                };
                var newId = staticDataService.CreateColorTheme(obj);
                Info = "Color theme " + model.NameEn + " successfully added with ID[" + newId + "]";
                return RedirectToAction("CreateColorTheme");
            }

            return View(model);
        }*/

        [HttpGet]
        public ActionResult CreateTag()
        {
            return View();
        }
        /*
        [HttpPost]
        public ActionResult CreateTag(TagViewModel model)
        {
            if (ModelState.IsValid)
            {
                var obj = new Tag()
                {
                    NameAm = model.NameAm,
                    NameEn = model.NameEn,
                    NameRu = model.NameRu
                };
                var newId = staticDataService.CreateTag(obj);
                Info = "Tag " + model.NameEn + " successfully added with ID[" + newId + "]";
                return RedirectToAction("CreateTag");
            }

            return View(model);
        }*/

        [HttpGet]
        public ActionResult CreateMediaType()
        {
            return View();
        }
        /*
        [HttpPost]
        public ActionResult CreateMediaType(PrintMediaTypeViewModel model)
        {
            if (ModelState.IsValid)
            {
                var obj = new PrintMediaType()
                {
                    Code = model.Code,
                    NameAm = model.NameAm,
                    NameEn = model.NameEn,
                    NameRu = model.NameRu,
                    DescriptionAm = model.DescriptionAm,
                    DescriptionEn = model.DescriptionEn,
                    DescriptionRu = model.DescriptionRu
                };
                staticDataService.CreatePrintMediaType(obj);
                Info = "Media type " + model.NameEn + " successfully added with CODE[" + model.Code + "]";
                return RedirectToAction("CreateMediaType");
            }

            return View(model);
        }*/

        [HttpGet]
        public ActionResult CreateDesignGroup()
        {
            return View();
        }
        /*
        [HttpPost]
        public ActionResult CreateDesignGroup(DesignGroupViewModel model)
        {
            if (ModelState.IsValid)
            {
                var obj = new DesignGroupDO()
                {
                    NameAm = model.NameAm,
                    NameEn = model.NameEn,
                    NameRu = model.NameRu
                };
                var newId = staticDataService.CreateDesignGroup(obj);
                Info = "Design group " + model.NameEn + " successfully added with ID[" + newId + "]";
                return RedirectToAction("CreateDesignGroup");
            }

            return View(model);
        }*/

        [HttpGet]
        public ActionResult CreateFont()
        {
            var model = new FontViewModel()
            {
                AllStyles = GetAllFontStyles(),
                AllLanguages = GetAllLanguages()
            };

            return View(model);
        }
        /*
        [HttpPost]
        public ActionResult CreateFont(FontViewModel model)
        {
            if (ModelState.IsValid)
            {
                HttpPostedFileBase file = Request.Files[0];

                FileStoreHelper.SaveFontFile(model.Name, file);

                var obj = new FontDO()
                {
                    Name = model.Name,
                    LanguageCode = model.LanguageCode,
                    IsUnicode = model.IsUnicode,
                    Style = model.Style,
                    FileName = file.FileName
                };
                var newId = staticDataService.CreateFont(obj);
                Info = "Font " + model.Name + " successfully added with ID[" + newId + "]";
                return RedirectToAction("CreateFont");
            }
            model.AllLanguages = GetAllLanguages();
            model.AllStyles = GetAllFontStyles();
            return View(model);
        }*/

        private List<SelectListItem> GetAllFontStyles()
        {
            var res = new List<SelectListItem>();
            res.Add(new SelectListItem() { 
                Value = "bo",
                Text = "Bold"
            });

            res.Add(new SelectListItem()
            {
                Value = "re",
                Text = "Regular"
            });

            res.Add(new SelectListItem()
            {
                Value = "it",
                Text = "Italic"
            });

            res.Add(new SelectListItem()
            {
                Value = "bi",
                Text = "Bold Italic"
            });

            return res;
        }

        private List<SelectListItem> GetAllLanguages()
        {
            var res = new List<SelectListItem>();
            res.Add(new SelectListItem()
            {
                Value = "",
                Text = ""
            });
            res.Add(new SelectListItem()
            {
                Value = "am",
                Text = "Armenian"
            });

            res.Add(new SelectListItem()
            {
                Value = "ru",
                Text = "Russian"
            });

            res.Add(new SelectListItem()
            {
                Value = "en",
                Text = "Roman/English"
            });
            return res;
        }

    }
}
